from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-15 14:02:27.275565
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 15, Apr, 2022
Time: 14:02:33
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.9652
Nobs: 627.000 HQIC: -49.3550
Log likelihood: 7633.35 FPE: 2.86989e-22
AIC: -49.6026 Det(Omega_mle): 2.48896e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.330324 0.063328 5.216 0.000
L1.Burgenland 0.105836 0.039820 2.658 0.008
L1.Kärnten -0.110560 0.020853 -5.302 0.000
L1.Niederösterreich 0.194876 0.083226 2.342 0.019
L1.Oberösterreich 0.120704 0.082023 1.472 0.141
L1.Salzburg 0.259441 0.042247 6.141 0.000
L1.Steiermark 0.043799 0.055610 0.788 0.431
L1.Tirol 0.104749 0.044996 2.328 0.020
L1.Vorarlberg -0.064865 0.039738 -1.632 0.103
L1.Wien 0.021965 0.072957 0.301 0.763
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.043572 0.135582 0.321 0.748
L1.Burgenland -0.036667 0.085253 -0.430 0.667
L1.Kärnten 0.041709 0.044646 0.934 0.350
L1.Niederösterreich -0.201270 0.178182 -1.130 0.259
L1.Oberösterreich 0.456144 0.175607 2.598 0.009
L1.Salzburg 0.282556 0.090448 3.124 0.002
L1.Steiermark 0.110504 0.119059 0.928 0.353
L1.Tirol 0.307187 0.096335 3.189 0.001
L1.Vorarlberg 0.027232 0.085078 0.320 0.749
L1.Wien -0.022574 0.156197 -0.145 0.885
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189056 0.032381 5.838 0.000
L1.Burgenland 0.089276 0.020361 4.385 0.000
L1.Kärnten -0.007453 0.010663 -0.699 0.485
L1.Niederösterreich 0.244162 0.042555 5.738 0.000
L1.Oberösterreich 0.161109 0.041940 3.841 0.000
L1.Salzburg 0.039764 0.021601 1.841 0.066
L1.Steiermark 0.027178 0.028435 0.956 0.339
L1.Tirol 0.083661 0.023007 3.636 0.000
L1.Vorarlberg 0.055280 0.020319 2.721 0.007
L1.Wien 0.119572 0.037304 3.205 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109374 0.032419 3.374 0.001
L1.Burgenland 0.043000 0.020385 2.109 0.035
L1.Kärnten -0.013253 0.010675 -1.241 0.214
L1.Niederösterreich 0.174018 0.042605 4.084 0.000
L1.Oberösterreich 0.334426 0.041989 7.965 0.000
L1.Salzburg 0.100144 0.021627 4.631 0.000
L1.Steiermark 0.112639 0.028468 3.957 0.000
L1.Tirol 0.091409 0.023034 3.968 0.000
L1.Vorarlberg 0.061225 0.020343 3.010 0.003
L1.Wien -0.013659 0.037348 -0.366 0.715
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109377 0.060675 1.803 0.071
L1.Burgenland -0.044327 0.038152 -1.162 0.245
L1.Kärnten -0.045814 0.019980 -2.293 0.022
L1.Niederösterreich 0.137533 0.079740 1.725 0.085
L1.Oberösterreich 0.163571 0.078587 2.081 0.037
L1.Salzburg 0.284015 0.040477 7.017 0.000
L1.Steiermark 0.059317 0.053281 1.113 0.266
L1.Tirol 0.160492 0.043111 3.723 0.000
L1.Vorarlberg 0.099396 0.038074 2.611 0.009
L1.Wien 0.078635 0.069901 1.125 0.261
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054057 0.047511 1.138 0.255
L1.Burgenland 0.026541 0.029874 0.888 0.374
L1.Kärnten 0.052952 0.015645 3.385 0.001
L1.Niederösterreich 0.196670 0.062439 3.150 0.002
L1.Oberösterreich 0.331862 0.061536 5.393 0.000
L1.Salzburg 0.036355 0.031695 1.147 0.251
L1.Steiermark 0.011369 0.041721 0.273 0.785
L1.Tirol 0.121646 0.033758 3.604 0.000
L1.Vorarlberg 0.067206 0.029813 2.254 0.024
L1.Wien 0.102221 0.054735 1.868 0.062
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167997 0.057094 2.942 0.003
L1.Burgenland 0.005328 0.035900 0.148 0.882
L1.Kärnten -0.065777 0.018801 -3.499 0.000
L1.Niederösterreich -0.103598 0.075033 -1.381 0.167
L1.Oberösterreich 0.206825 0.073948 2.797 0.005
L1.Salzburg 0.054478 0.038088 1.430 0.153
L1.Steiermark 0.246053 0.050136 4.908 0.000
L1.Tirol 0.501558 0.040567 12.364 0.000
L1.Vorarlberg 0.063885 0.035826 1.783 0.075
L1.Wien -0.074277 0.065775 -1.129 0.259
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.147539 0.063332 2.330 0.020
L1.Burgenland -0.001917 0.039823 -0.048 0.962
L1.Kärnten 0.062517 0.020855 2.998 0.003
L1.Niederösterreich 0.169107 0.083231 2.032 0.042
L1.Oberösterreich -0.053532 0.082028 -0.653 0.514
L1.Salzburg 0.207160 0.042249 4.903 0.000
L1.Steiermark 0.139881 0.055614 2.515 0.012
L1.Tirol 0.058107 0.044999 1.291 0.197
L1.Vorarlberg 0.147970 0.039741 3.723 0.000
L1.Wien 0.125575 0.072962 1.721 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.380686 0.037326 10.199 0.000
L1.Burgenland -0.003320 0.023470 -0.141 0.888
L1.Kärnten -0.020729 0.012291 -1.687 0.092
L1.Niederösterreich 0.206086 0.049054 4.201 0.000
L1.Oberösterreich 0.229955 0.048345 4.757 0.000
L1.Salzburg 0.037502 0.024900 1.506 0.132
L1.Steiermark -0.012995 0.032777 -0.396 0.692
L1.Tirol 0.089345 0.026521 3.369 0.001
L1.Vorarlberg 0.052422 0.023422 2.238 0.025
L1.Wien 0.043555 0.043001 1.013 0.311
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036897 0.111373 0.173638 0.140523 0.101882 0.081877 0.037636 0.211338
Kärnten 0.036897 1.000000 -0.024143 0.132255 0.050637 0.086920 0.443740 -0.065498 0.090097
Niederösterreich 0.111373 -0.024143 1.000000 0.317350 0.125779 0.277694 0.070065 0.156338 0.293746
Oberösterreich 0.173638 0.132255 0.317350 1.000000 0.216508 0.299580 0.168247 0.139939 0.241703
Salzburg 0.140523 0.050637 0.125779 0.216508 1.000000 0.127770 0.094283 0.107976 0.126332
Steiermark 0.101882 0.086920 0.277694 0.299580 0.127770 1.000000 0.136277 0.110667 0.039605
Tirol 0.081877 0.443740 0.070065 0.168247 0.094283 0.136277 1.000000 0.066046 0.151974
Vorarlberg 0.037636 -0.065498 0.156338 0.139939 0.107976 0.110667 0.066046 1.000000 -0.003684
Wien 0.211338 0.090097 0.293746 0.241703 0.126332 0.039605 0.151974 -0.003684 1.000000